﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:DM_SWJG
    /// </summary>
    public partial class DM_SWJG
    {
        public DM_SWJG()
        { }
        #region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string SWJG_DM)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ltais.DM_SWJG");
            strSql.Append(" where SWJG_DM=@SWJG_DM ");
            SqlParameter[] parameters = {
					new SqlParameter("@SWJG_DM", SqlDbType.NVarChar,11)			};
            parameters[0].Value = SWJG_DM;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(EnterpriseFund.Model.DM_SWJG model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ltais.DM_SWJG(");
            strSql.Append("SWJG_DM,SWJG_MC,SWJG_JC,SWJG_BZ,SJ_SWJG_DM,NSR_SWJG_BZ,JGJC_DM,SWJG_JG,SWJG_YB,SWJG_DZ,SWJG_DH,CZDH,DYDZ,XZQH_DM,SWJG_FZR_DM,TS_NSRSBH,YXWS,JBDM,JCDM,YXBZ)");
            strSql.Append(" values (");
            strSql.Append("@SWJG_DM,@SWJG_MC,@SWJG_JC,@SWJG_BZ,@SJ_SWJG_DM,@NSR_SWJG_BZ,@JGJC_DM,@SWJG_JG,@SWJG_YB,@SWJG_DZ,@SWJG_DH,@CZDH,@DYDZ,@XZQH_DM,@SWJG_FZR_DM,@TS_NSRSBH,@YXWS,@JBDM,@JCDM,@YXBZ)");
            SqlParameter[] parameters = {
					new SqlParameter("@SWJG_DM", SqlDbType.NVarChar,11),
					new SqlParameter("@SWJG_MC", SqlDbType.NVarChar,60),
					new SqlParameter("@SWJG_JC", SqlDbType.NVarChar,50),
					new SqlParameter("@SWJG_BZ", SqlDbType.NVarChar,1),
					new SqlParameter("@SJ_SWJG_DM", SqlDbType.NVarChar,11),
					new SqlParameter("@NSR_SWJG_BZ", SqlDbType.NVarChar,1),
					new SqlParameter("@JGJC_DM", SqlDbType.NVarChar,2),
					new SqlParameter("@SWJG_JG", SqlDbType.NVarChar,10),
					new SqlParameter("@SWJG_YB", SqlDbType.NVarChar,6),
					new SqlParameter("@SWJG_DZ", SqlDbType.NVarChar,50),
					new SqlParameter("@SWJG_DH", SqlDbType.NVarChar,20),
					new SqlParameter("@CZDH", SqlDbType.NVarChar,20),
					new SqlParameter("@DYDZ", SqlDbType.NVarChar,30),
					new SqlParameter("@XZQH_DM", SqlDbType.NVarChar,6),
					new SqlParameter("@SWJG_FZR_DM", SqlDbType.NVarChar,11),
					new SqlParameter("@TS_NSRSBH", SqlDbType.NVarChar,20),
					new SqlParameter("@YXWS", SqlDbType.SmallInt,2),
					new SqlParameter("@JBDM", SqlDbType.NVarChar,30),
					new SqlParameter("@JCDM", SqlDbType.NVarChar,2),
					new SqlParameter("@YXBZ", SqlDbType.NVarChar,1)};
            parameters[0].Value = model.SWJG_DM;
            parameters[1].Value = model.SWJG_MC;
            parameters[2].Value = model.SWJG_JC;
            parameters[3].Value = model.SWJG_BZ;
            parameters[4].Value = model.SJ_SWJG_DM;
            parameters[5].Value = model.NSR_SWJG_BZ;
            parameters[6].Value = model.JGJC_DM;
            parameters[7].Value = model.SWJG_JG;
            parameters[8].Value = model.SWJG_YB;
            parameters[9].Value = model.SWJG_DZ;
            parameters[10].Value = model.SWJG_DH;
            parameters[11].Value = model.CZDH;
            parameters[12].Value = model.DYDZ;
            parameters[13].Value = model.XZQH_DM;
            parameters[14].Value = model.SWJG_FZR_DM;
            parameters[15].Value = model.TS_NSRSBH;
            parameters[16].Value = model.YXWS;
            parameters[17].Value = model.JBDM;
            parameters[18].Value = model.JCDM;
            parameters[19].Value = model.YXBZ;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(EnterpriseFund.Model.DM_SWJG model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ltais.DM_SWJG set ");
            strSql.Append("SWJG_MC=@SWJG_MC,");
            strSql.Append("SWJG_JC=@SWJG_JC,");
            strSql.Append("SWJG_BZ=@SWJG_BZ,");
            strSql.Append("SJ_SWJG_DM=@SJ_SWJG_DM,");
            strSql.Append("NSR_SWJG_BZ=@NSR_SWJG_BZ,");
            strSql.Append("JGJC_DM=@JGJC_DM,");
            strSql.Append("SWJG_JG=@SWJG_JG,");
            strSql.Append("SWJG_YB=@SWJG_YB,");
            strSql.Append("SWJG_DZ=@SWJG_DZ,");
            strSql.Append("SWJG_DH=@SWJG_DH,");
            strSql.Append("CZDH=@CZDH,");
            strSql.Append("DYDZ=@DYDZ,");
            strSql.Append("XZQH_DM=@XZQH_DM,");
            strSql.Append("SWJG_FZR_DM=@SWJG_FZR_DM,");
            strSql.Append("TS_NSRSBH=@TS_NSRSBH,");
            strSql.Append("YXWS=@YXWS,");
            strSql.Append("JBDM=@JBDM,");
            strSql.Append("JCDM=@JCDM,");
            strSql.Append("YXBZ=@YXBZ");
            strSql.Append(" where SWJG_DM=@SWJG_DM ");
            SqlParameter[] parameters = {
					new SqlParameter("@SWJG_MC", SqlDbType.NVarChar,60),
					new SqlParameter("@SWJG_JC", SqlDbType.NVarChar,50),
					new SqlParameter("@SWJG_BZ", SqlDbType.NVarChar,1),
					new SqlParameter("@SJ_SWJG_DM", SqlDbType.NVarChar,11),
					new SqlParameter("@NSR_SWJG_BZ", SqlDbType.NVarChar,1),
					new SqlParameter("@JGJC_DM", SqlDbType.NVarChar,2),
					new SqlParameter("@SWJG_JG", SqlDbType.NVarChar,10),
					new SqlParameter("@SWJG_YB", SqlDbType.NVarChar,6),
					new SqlParameter("@SWJG_DZ", SqlDbType.NVarChar,50),
					new SqlParameter("@SWJG_DH", SqlDbType.NVarChar,20),
					new SqlParameter("@CZDH", SqlDbType.NVarChar,20),
					new SqlParameter("@DYDZ", SqlDbType.NVarChar,30),
					new SqlParameter("@XZQH_DM", SqlDbType.NVarChar,6),
					new SqlParameter("@SWJG_FZR_DM", SqlDbType.NVarChar,11),
					new SqlParameter("@TS_NSRSBH", SqlDbType.NVarChar,20),
					new SqlParameter("@YXWS", SqlDbType.SmallInt,2),
					new SqlParameter("@JBDM", SqlDbType.NVarChar,30),
					new SqlParameter("@JCDM", SqlDbType.NVarChar,2),
					new SqlParameter("@YXBZ", SqlDbType.NVarChar,1),
					new SqlParameter("@SWJG_DM", SqlDbType.NVarChar,11)};
            parameters[0].Value = model.SWJG_MC;
            parameters[1].Value = model.SWJG_JC;
            parameters[2].Value = model.SWJG_BZ;
            parameters[3].Value = model.SJ_SWJG_DM;
            parameters[4].Value = model.NSR_SWJG_BZ;
            parameters[5].Value = model.JGJC_DM;
            parameters[6].Value = model.SWJG_JG;
            parameters[7].Value = model.SWJG_YB;
            parameters[8].Value = model.SWJG_DZ;
            parameters[9].Value = model.SWJG_DH;
            parameters[10].Value = model.CZDH;
            parameters[11].Value = model.DYDZ;
            parameters[12].Value = model.XZQH_DM;
            parameters[13].Value = model.SWJG_FZR_DM;
            parameters[14].Value = model.TS_NSRSBH;
            parameters[15].Value = model.YXWS;
            parameters[16].Value = model.JBDM;
            parameters[17].Value = model.JCDM;
            parameters[18].Value = model.YXBZ;
            parameters[19].Value = model.SWJG_DM;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string SWJG_DM)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ltais.DM_SWJG ");
            strSql.Append(" where SWJG_DM=@SWJG_DM ");
            SqlParameter[] parameters = {
					new SqlParameter("@SWJG_DM", SqlDbType.NVarChar,11)			};
            parameters[0].Value = SWJG_DM;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string SWJG_DMlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ltais.DM_SWJG ");
            strSql.Append(" where SWJG_DM in (" + SWJG_DMlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.DM_SWJG GetModel(string SWJG_DM)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 SWJG_DM,SWJG_MC,SWJG_JC,SWJG_BZ,SJ_SWJG_DM,NSR_SWJG_BZ,JGJC_DM,SWJG_JG,SWJG_YB,SWJG_DZ,SWJG_DH,CZDH,DYDZ,XZQH_DM,SWJG_FZR_DM,TS_NSRSBH,YXWS,JBDM,JCDM,YXBZ from ltais.DM_SWJG ");
            strSql.Append(" where SWJG_DM=@SWJG_DM ");
            SqlParameter[] parameters = {
					new SqlParameter("@SWJG_DM", SqlDbType.NVarChar,11)			};
            parameters[0].Value = SWJG_DM;

            EnterpriseFund.Model.DM_SWJG model = new EnterpriseFund.Model.DM_SWJG();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.DM_SWJG DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.DM_SWJG model = new EnterpriseFund.Model.DM_SWJG();
            if (row != null)
            {
                if (row["SWJG_DM"] != null)
                {
                    model.SWJG_DM = row["SWJG_DM"].ToString();
                }
                if (row["SWJG_MC"] != null)
                {
                    model.SWJG_MC = row["SWJG_MC"].ToString();
                }
                if (row["SWJG_JC"] != null)
                {
                    model.SWJG_JC = row["SWJG_JC"].ToString();
                }
                if (row["SWJG_BZ"] != null)
                {
                    model.SWJG_BZ = row["SWJG_BZ"].ToString();
                }
                if (row["SJ_SWJG_DM"] != null)
                {
                    model.SJ_SWJG_DM = row["SJ_SWJG_DM"].ToString();
                }
                if (row["NSR_SWJG_BZ"] != null)
                {
                    model.NSR_SWJG_BZ = row["NSR_SWJG_BZ"].ToString();
                }
                if (row["JGJC_DM"] != null)
                {
                    model.JGJC_DM = row["JGJC_DM"].ToString();
                }
                if (row["SWJG_JG"] != null)
                {
                    model.SWJG_JG = row["SWJG_JG"].ToString();
                }
                if (row["SWJG_YB"] != null)
                {
                    model.SWJG_YB = row["SWJG_YB"].ToString();
                }
                if (row["SWJG_DZ"] != null)
                {
                    model.SWJG_DZ = row["SWJG_DZ"].ToString();
                }
                if (row["SWJG_DH"] != null)
                {
                    model.SWJG_DH = row["SWJG_DH"].ToString();
                }
                if (row["CZDH"] != null)
                {
                    model.CZDH = row["CZDH"].ToString();
                }
                if (row["DYDZ"] != null)
                {
                    model.DYDZ = row["DYDZ"].ToString();
                }
                if (row["XZQH_DM"] != null)
                {
                    model.XZQH_DM = row["XZQH_DM"].ToString();
                }
                if (row["SWJG_FZR_DM"] != null)
                {
                    model.SWJG_FZR_DM = row["SWJG_FZR_DM"].ToString();
                }
                if (row["TS_NSRSBH"] != null)
                {
                    model.TS_NSRSBH = row["TS_NSRSBH"].ToString();
                }
                if (row["YXWS"] != null && row["YXWS"].ToString() != "")
                {
                    model.YXWS = int.Parse(row["YXWS"].ToString());
                }
                if (row["JBDM"] != null)
                {
                    model.JBDM = row["JBDM"].ToString();
                }
                if (row["JCDM"] != null)
                {
                    model.JCDM = row["JCDM"].ToString();
                }
                if (row["YXBZ"] != null)
                {
                    model.YXBZ = row["YXBZ"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select SWJG_DM,SWJG_MC,SWJG_JC,SWJG_BZ,SJ_SWJG_DM,NSR_SWJG_BZ,JGJC_DM,SWJG_JG,SWJG_YB,SWJG_DZ,SWJG_DH,CZDH,DYDZ,XZQH_DM,SWJG_FZR_DM,TS_NSRSBH,YXWS,JBDM,JCDM,YXBZ ");
            strSql.Append(" FROM ltais.DM_SWJG ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" SWJG_DM,SWJG_MC,SWJG_JC,SWJG_BZ,SJ_SWJG_DM,NSR_SWJG_BZ,JGJC_DM,SWJG_JG,SWJG_YB,SWJG_DZ,SWJG_DH,CZDH,DYDZ,XZQH_DM,SWJG_FZR_DM,TS_NSRSBH,YXWS,JBDM,JCDM,YXBZ ");
            strSql.Append(" FROM ltais.DM_SWJG ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM ltais.DM_SWJG ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.SWJG_DM desc");
            }
            strSql.Append(")AS Row, T.*  from ltais.DM_SWJG T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "DM_SWJG";
            parameters[1].Value = "SWJG_DM";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

